package cn.com.blueInfo.bpm.person.controller;

import cn.com.blueInfo.bpm.common.controller.BaseController;
import cn.com.blueInfo.bpm.common.validation.Create;
import cn.com.blueInfo.bpm.common.validation.Update;
import cn.com.blueInfo.bpm.common.validation.UpdatePartial;
import cn.com.blueInfo.bpm.person.request.UserIdentityDTO;
import cn.com.blueInfo.bpm.person.response.UserIdentityVO;
import cn.com.blueInfo.bpm.person.service.UserIdentityService;
import cn.com.blueInfo.utils.result.ResultInfo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.groups.Default;
import java.util.List;

/**
 * 员工身份信息表 前端控制器
 * @author suxch
 * @since 2025-08-24 01:39:52
 */
@Tag(name = "员工身份信息 接口")
@RestController
@RequestMapping("/person/userIdentity")
public class UserIdentityController extends BaseController {

    @Autowired
    private UserIdentityService userIdentityService;

    /**
     * 新建员工身份信息
     * @param userIdentityDTO 员工身份信息参数
     * @return ResultInfo
     */
    @Operation(summary = "新增员工身份信息")
    @PostMapping("/addInfo")
    public ResultInfo<Integer> createUserIdentity(
            @Validated({Create.class, Default.class}) @RequestBody UserIdentityDTO userIdentityDTO) {
        return userIdentityService.addUserIdentity(userIdentityDTO);
    }

    /**
     * 批量新建员工身份信息
     * @param userIdentityDTOList 员工身份信息参数列表
     * @return ResultInfo
     */
    @Operation(summary = "新增员工身份信息")
    @PostMapping("/addInfoList")
    public ResultInfo<Integer> batchCreateUserIdentity(
            @Validated({Create.class, Default.class}) @RequestBody List<UserIdentityDTO> userIdentityDTOList) {
        return userIdentityService.batchAddUserIdentity(userIdentityDTOList);
    }

    /**
     * 根据ID删除员工身份信息
     * @param userIdentityId 员工身份信息ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID删除员工身份信息")
    @DeleteMapping("/removeInfo/{userIdentityId}")
    public ResultInfo<Integer> deleteUserIdentityById(
            @Parameter(name = "ID") @PathVariable Long userIdentityId) {
        return userIdentityService.removeUserIdentity(userIdentityId);
    }

    /**
     * 批量根据ID删除员工身份信息
     * @param userIdentityIdList 员工身份信息ID列表
     * @return ResultInfo
     */
    @Operation(summary = "根据ID删除员工身份信息")
    @DeleteMapping("/removeInfo/{userIdentityIdList}")
    public ResultInfo<Integer> batchDeleteUserIdentityById(
            @Parameter(name = "ID") @PathVariable List<Long> userIdentityIdList) {
        return userIdentityService.batchRemoveUserIdentity(userIdentityIdList);
    }

    /**
     * 根据ID全量更新员工身份信息
     * @param userIdentityId 员工身份信息ID
     * @param userIdentityDTO 员工身份信息参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID全量更新员工身份信息")
    @PutMapping("/modifyInfo/{userIdentityId}")
    public ResultInfo<Integer> updateUserIdentityFull(
            @Parameter(name = "ID") @PathVariable Long userIdentityId,
            @Validated({Update.class, Default.class}) @RequestBody UserIdentityDTO userIdentityDTO) {
        validateUpdateId(userIdentityId, userIdentityDTO.getId());
        return userIdentityService.modifyUserIdentity(userIdentityDTO);
    }

    /**
     * 根据ID部分更新员工身份信息
     * @param userIdentityId 员工身份信息ID
     * @param userIdentityUpdatePartialDTO 员工身份信息参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID部分更新员工身份信息")
    @PatchMapping("/modifyPartialInfo/{userIdentityId}")
    public ResultInfo<Integer> updateUserIdentityPartial(
            @Parameter(name = "ID") @PathVariable Long userIdentityId,
            @Validated({UpdatePartial.class, Default.class}) @RequestBody
            UserIdentityDTO.UpdatePartialDTO userIdentityUpdatePartialDTO) {
        validateUpdateId(userIdentityId, userIdentityUpdatePartialDTO.getId());
        return userIdentityService.modifyUserIdentityPartial(userIdentityUpdatePartialDTO);
    }

    /**
     * 根据ID查询员工身份信息
     * @param userIdentityId 员工身份信息ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID查询员工身份信息")
    @GetMapping("/getInfo/{userIdentityId}")
    public ResultInfo<UserIdentityVO> getUserIdentityById(
            @Parameter(name = "ID") @PathVariable Long userIdentityId) {
        return userIdentityService.queryUserIdentityById(userIdentityId);
    }

    /**
     * 分页查询员工身份信息
     * @param userIdentityQueryDTO 员工身份信息参数
     * @return ResultInfo
     */
    @Operation(summary = "分页查询员工身份信息")
    @GetMapping("/getInfos")
    public ResultInfo<Page<UserIdentityVO>> getUserIdentityPage(
            @Validated UserIdentityDTO.QueryDTO userIdentityQueryDTO) {
        return userIdentityService.queryUserIdentityPage(userIdentityQueryDTO);
    }

    /**
     * 根据条件查询员工身份信息
     * @param userIdentityQueryDTO 员工身份信息参数
     * @return ResultInfo
     */
    @Operation(summary = "根据条件查询员工身份信息")
    @GetMapping("/getInfoList")
    public ResultInfo<List<UserIdentityVO>> getUserIdentityList(
            @Validated UserIdentityDTO.QueryDTO userIdentityQueryDTO) {
        return userIdentityService.queryUserIdentityList(userIdentityQueryDTO);
    }

}
